package com.shangjinrong.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shangjinrong.domain.UserInfo;
import com.shangjinrong.domain.dto.UserInfoQuery;
import com.shangjinrong.result.R;
import com.shangjinrong.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("admin/userInfo")
@Slf4j
public class AdminUserInfoController {
    @Autowired
    UserInfoService userInfoService;

    @GetMapping("list")
    public R list(){
        return R.ok().data("list",userInfoService.list()).message("ok");
    }

    @GetMapping("paging/{current}/{size}")
    public R paging(@PathVariable long current,@PathVariable long size,UserInfoQuery query){
        Page<UserInfo> page = new Page<>(current,size);
        userInfoService.paging(page,query);
        return R.ok().data("paging",page).message("ok");
    }

    @GetMapping("getById/{id}")
    public R getById(@PathVariable long id){
        return R.ok().data("userInfo",userInfoService.getById(id));
    }

    @PutMapping("/lock/{id}/{status}")
    public R lock(
            @PathVariable("id") Long id,
            @PathVariable("status")Integer status){
        userInfoService.lock(id,status);
        return R.ok().message(status==1?"解锁成功":"锁定成功");
    }






}
